<?php
declare(strict_types = 1);
namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;
use function GuzzleHttp\json_decode;

class Sysconfig extends BasePssModel
{

    public $table = 'sysconfig';

    protected $code = 'mall_goods_best_rule';

    /**
     * 获取商城模板
     */
    public function getShopTemplate()
    {
        return $this->info([
            'code' => $this->code
        ]);
    }

    /**
     * 更新商城模板
     */
    public function updateContents(string $template, bool $is_sync)
    {
        return $this->where('code', $this->code)->update([
            'contents' => $template,
            'value' => $is_sync ? 1 : 0,
            'small_type' => 0,
            'md' => time()
        ]);
    }
    
    /**
     * 获取第三方业务对接配置info
     *
     * @param string code
     * @return contents
     */
    public function getConfigByEventsValue(string $code)
    {
        $select = [
            'contents'
        ];
        $where = [
            'code'   => $code,
            'status' => 1
        ];
        $row = $this->info($where, $select);
        return  $row ?  @json_decode($row['contents'],true): '';
    }
}
